package ui;

import Tools.EventHandler;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Bar extends JMenuBar {



    private EventHandler eventHandler; //引入事件处理器
    public void setEventHandler(EventHandler eventHandler) {
        this.eventHandler = eventHandler;
    }

    private DrawingBoard drawingBoard;
    public void setDrawingBoard(DrawingBoard drawingBoard) {
        this.drawingBoard = drawingBoard;
    }


    private MyPanel panel;//引入Panel
    public void setPanel(MyPanel panel) {
        this.panel = panel;
    }
    public JToggleButton[] jToggleButtonsOfFigures = new JToggleButton[5];   //保存按钮列表
    public String[] jToggleButtonsOfFiguresTitles = new String[]{"直线", "矩形", "圆", "直角三角形", "等腰三角形"};
    public JToggleButton[] jToggleButtonsOfAttribute = new JToggleButton[9];
    public String[] jToggleButtonsOfAttributeTitles = new String[]{"选择颜色", "填充颜色", "选择大小", "拉伸图像", "移动图像", "清除", "删除","保存","打开文件"};
    public int FigureButtons_num = 5;
    public int AttributeButtons_num = 9;
    public int buttons_num = 12;                //保存按钮数量


    //构造方法
    public Bar(){init();}
    public void init() {


        //创建形状按钮
        for (int i = 0; i < 5; i++) {
            //创建形状按钮
            jToggleButtonsOfFigures[i] = new JToggleButton(jToggleButtonsOfFiguresTitles[i]);
            //绑定事件
            Button_addListener(jToggleButtonsOfFigures[i]);
            add(jToggleButtonsOfFigures[i]);

        }

        for (int i = 0; i < 9; i++){
            //创建功能按钮
            jToggleButtonsOfAttribute[i] = new JToggleButton(jToggleButtonsOfAttributeTitles[i]);
            //绑定事件
            Button_addListener(jToggleButtonsOfAttribute[i]);
            add(jToggleButtonsOfAttribute[i]);
        }

    }


    //为按钮绑定事件
    private void Button_addListener(JToggleButton jToggleButton) {
                jToggleButton.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        eventHandler.Button_Event(jToggleButton);
                    }
                });

        }



}
